//
//  JJUUIDManager.m
//  CaiFuYiDianTong
//
//  Created by WcjMBP on 2016/12/23.
//  Copyright © 2016年 WCJ. All rights reserved.
//

#import "JJKeyChainManager.h"

#import "JJUUIDManager.h"

@implementation JJUUIDManager

static NSString * const KEY_IN_KEYCHAIN = @"com.94hwpro.uuid";


+(void)saveUUID:(NSString *)uuid{
    if (uuid && uuid.length > 0) {
        [JJKeyChainManager save:KEY_IN_KEYCHAIN data:uuid];
    }
}


+(NSString *)getUUID{
    //先获取keychain里面的UUID字段，看是否存在
    NSString *uuid = (NSString *)[JJKeyChainManager load:KEY_IN_KEYCHAIN];
    
    //如果不存在则为首次获取UUID，所以获取保存。
    if (!uuid || uuid.length == 0) {
        CFUUIDRef puuid = CFUUIDCreate( nil );
        
        CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
        
        uuid = [NSString stringWithFormat:@"%@", uuidString];
        
        [self saveUUID:uuid];
        
        CFRelease(puuid);
        
        CFRelease(uuidString);
    }
    
    return uuid;
}



+(void)deleteUUID{
    [JJKeyChainManager delete:KEY_IN_KEYCHAIN];
}

@end
